package day17.edu;
// Created: 17/09/2025, ChangJiang Ru

import org.junit.Test;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description: API of JDK 8.0, LocalDate, LocalTime, LocalDateTime
 */
public class DateTimeTest {
    @Test
    public void test1()
    {
        LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        LocalDateTime localDateTime = LocalDateTime.now();

        System.out.println(localDate);
        System.out.println(localTime);
        System.out.println(localDateTime);

        System.out.println("======");
        LocalDate localDate1 = LocalDate.of(2024, 12, 23);
        System.out.println(localDate1);
        LocalDateTime localDateTime1 = LocalDateTime.of(2022,1, 2, 12,23,34);
        System.out.println(localDateTime1);

        System.out.println("======");
        LocalDateTime localDateTime2 = LocalDateTime.now();
        System.out.println(localDateTime2.getDayOfMonth());
        System.out.println(localDateTime2.getDayOfWeek());

        System.out.println("======");
        LocalDateTime localDateTime3 = localDateTime2.withDayOfMonth(13);
        System.out.println(localDateTime2);
        System.out.println(localDateTime3);

        System.out.println("=======");
        LocalDateTime localDateTime4 = localDateTime3.plusDays(2);
        System.out.println(localDateTime4);
    }

    /**
     * @Description: API of JDK8: instant
     */
    @Test
    public void test2()
    {
        Instant instant = Instant.now();
        System.out.println(instant);

        OffsetDateTime instant1 = instant.atOffset(ZoneOffset.ofHours(8));
        System.out.println(instant1);

        System.out.println("======");
        Instant instant2 = Instant.ofEpochMilli(1758115356972L);
        System.out.println(instant2);

        System.out.println("=======");
        long epochMilli = instant.toEpochMilli();
        System.out.println(epochMilli);
        System.out.println(new Date().getTime());
    }
    
    @Test
    public void test3()
    {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.now();
        String strDateTime = dateTimeFormatter.format(localDateTime);
        System.out.println(strDateTime);
    }
    
    @Test
    public void test4()
    {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);
        Date time = calendar.getTime();
        System.out.println(time);

        calendar.add(Calendar.DAY_OF_YEAR, 100);
        Date newTime = calendar.getTime();
        System.out.println(newTime);
    }


}
